package test.designpattern.simpleFactory;

public interface ICalculator {
    double getResult(double num1, double num2) throws Exception;
}

class Add implements ICalculator {
    @Override
    public double getResult(double num1, double num2) {
        return num1 + num2;
    }
}

class Sub implements ICalculator {
    @Override
    public double getResult(double num1, double num2) {
        return num1 - num2;
    }
}

class Mul implements ICalculator {
    @Override
    public double getResult(double num1, double num2) {
        return num1 * num2;
    }
}

class Div implements ICalculator {
    @Override
    public double getResult(double num1, double num2) throws Exception {
        if (num2 == 0) {
            throw new Exception("除数不能为0");
        }
        return num1 / num2;
    }
}
